package com.ghck.server.bkcontroller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.ghck.server.service.aggregation.SellerAggregationService;
import com.ghck.shop.model.Page;
import com.ghck.shop.model.Seller;
import com.ghck.shop.service.SellerService;

@Controller
@RequestMapping(value="/system/seller")
public class AdminSellerController {

	@Autowired
	private SellerService sellerService;
	@Autowired
	private SellerAggregationService sellerAggregationService;
	
	@RequestMapping(value="/list",method=RequestMethod.GET)
	public String main(Seller seller,
			@RequestParam(defaultValue = "1") Integer currentPage,
			@RequestParam(defaultValue = "10") Integer pageSize,
            HttpServletRequest request){
		int start = 0;
		if(currentPage > 0 ){
			start = ((currentPage-1)*pageSize);
		}
		Page<Seller> page = new Page<Seller>(currentPage);
		page.setPageSize(pageSize);
		List<Seller> list = sellerService.listSellers(seller, start, pageSize);
		page.setResultRows(list);
		page.setTotalRow(sellerService.countListSellers(seller));
		request.setAttribute("page", page);
		return "back/seller/list";
	}
	
	@RequestMapping(value="/sellerPass/{id}",method = RequestMethod.GET)
	public String sellerPass(@PathVariable("id")Integer id){
		Seller seller = new Seller();
		seller.setId(id);
		sellerAggregationService.sellerPass(seller);
		return "redirect:/system/seller/list";
	}
	
	@RequestMapping(value="/sellerReject/{id}",method = RequestMethod.GET)
	public String sellerReject(@PathVariable("id")Integer id){
		Seller seller = new Seller();
		seller.setId(id);
		sellerService.sellerReject(seller);
		return "redirect:/system/seller/list";
	}
}
